﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Core;

namespace DAL
{
    public class ReSubjectiveQuestionDAL : SyncBase<Model.ReSubjectiveQuestion>
    {
        static ReSubjectiveQuestionDAL()
        {
            StringBuilder strSql = new StringBuilder();
            ReSubjectiveQuestionDAL.addSQL = @"insert into TempReSubjectiveQuestion(
ArrangeID,StudentID,StudentName,QuestionCombinationID,QuestionID,StemID,SubAnswer,AnswerResID,AnswerResUrl,IsCorrect,Comment,IsRight,score,Route,ResourceType,CorrectTime)
 values (
@ArrangeID,@StudentID,@StudentName,@QuestionCombinationID,@QuestionID,@StemID,@SubAnswer,@AnswerResID,@AnswerResUrl,@IsCorrect,@Comment,@IsRight,@score,@Route,@ResourceType,@CorrectTime)";
            ReSubjectiveQuestionDAL.tbName = "TempReSubjectiveQuestion";
            ReSubjectiveQuestionDAL.remoteUrl = "/Ayyfford/AddReSubjectiveQuestion";
            ReSubjectiveQuestionDAL.setVal = (lt) =>
            {
                StringBuilder sb = new StringBuilder();
                string _ids = string.Empty;
                if (lt != null && lt.Count > 0)
                {
                    lt.ForEach(t =>
                    {
                        _ids += t.ID + ",";
                        sb.AppendFormat("({0}, {1}, {2}, {3}, {4}, {5}, {6},{7},{8}, {9}, {10}, {11}, {12}, {13},{14},{15}),",
                            t.ArrangeID.NullNumber(), t.StudentID.NullNumber(), t.StudentName.NullString(), t.QuestionCombinationID.NullNumber(),
                            t.QuestionID.NullNumber(), t.StemID.NullNumber(), t.SubAnswer.NullString(),
                            t.AnswerResID.NullNumber(), t.AnswerResUrl.NullString(), t.IsCorrect ? 1 : 0,
                            t.Comment.NullString(), t.IsRight ? 1 : 0, t.score.NullNumber(),
                            t.Route.NullString(), t.ResourceType.NullString(), t.CorrectTime.NullDate());
                    });
                }
                return new Tuple<string, string>(sb.ToString(), _ids);
            };
        }

        new public static void SaveEntity(Model.ReSubjectiveQuestion t)
        {
            SyncBase<Model.ReSubjectiveQuestion>.SaveEntity(t);
        }

        new public static void AsyncData()
        {
            SyncBase<Model.ReSubjectiveQuestion>.AsyncData();
        }
    }
}
